package com.imooc.framework.thread;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class LockSupportDemo implements Runnable{
    @Override
    public void run() {
        try {
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName() + "进入线程");
            LockSupport.park();
            System.out.println(Thread.currentThread().getName() + "运行结束");
            System.out.println(Thread.currentThread().getName() + "是否中断：" + Thread.currentThread().isInterrupted() );

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        LockSupportDemo lockSupportDemo = new LockSupportDemo();
        Thread t = new Thread(lockSupportDemo);
        t.setName("thread");
        t.start();

        Thread.sleep(3000);
        t.interrupt();
        System.out.println("t1线程已启动，但内部lockSupport进行park");
        System.out.println("main线程结束");
        LockSupport.unpark(t);
    }
}
